package com.elitetyc.eliteim.common.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

/**
 * @author yuanchao.tan
 * @version 1.0
 * @description TODO
 * @Date 2022/6/16 16:58
 */
@Component
public class SpringBeanFactory implements ApplicationContextAware {

    public static<T> T getBean(Class<T> clazz){
        return context.getBean(clazz);
    }

    public static<T> List<T> getBeanList(Class<T> clazz){
        return (List<T>) context.getBeansOfType(clazz).values();
    }

    private static ApplicationContext context;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringBeanFactory.context = applicationContext;
    }


}
